package com.lashou.chunshen.lashoutuangou.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lashou.chunshen.lashoutuangou.R;
import com.lashou.chunshen.lashoutuangou.bean.HomeBanner;
import com.lashou.chunshen.lashoutuangou.tools.PicassoUtils;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**购物shopping的gridview(Center_banner)
 * Created by Administrator on 2016/8/30.
 */
public class HomeShoppingGvAdapter extends BaseAdapter {
    HomeBanner datas;
    private Activity mActivity;
    public HomeShoppingGvAdapter(Activity activity, HomeBanner datas) {
        mActivity = activity;
        this.datas = datas;
    }

    @Override public int getCount() {
        return datas.getResults().getCenter_banner().size();
    }

    @Override
    public Object getItem(int position) {
        return datas.getResults().getCenter_banner().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolderClass holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mActivity).inflate(R.layout.griditem_home_special, null, false);
            holder = new ViewHolderClass(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolderClass) convertView.getTag();
        }
        HomeBanner.ResultsBean.CenterBannerBean bean = datas.getResults().getCenter_banner().get(position);
        if (null != bean) {
            PicassoUtils.loadImageViewHolder(mActivity,bean.getImg_mid(),R.drawable.home_class_default_icon,holder.imageView);
            holder.tvTitle.setText(bean.getMain_title());
            holder.tvDesc.setText(bean.getSub_title());
        }
        //设置Main_Title的颜色
        switch (position){
            case 0:
                holder.tvTitle.setTextColor(Color.BLUE);
                break;
            case 1:
                holder.tvTitle.setTextColor(Color.RED);
                break;
            case 2:
                holder.tvTitle.setTextColor(Color.GREEN);
                break;
            case 3:
                holder.tvTitle.setTextColor(Color.YELLOW);
                break;
        }
        return convertView;
    }
    public class ViewHolderClass {
        @InjectView(R.id.iv_ad)
        ImageView imageView;
        @InjectView(R.id.tv_ad_title)
        TextView tvTitle;
        @InjectView(R.id.tv_ad_desc)
        TextView tvDesc;
        public ViewHolderClass(View view) {
            ButterKnife.inject(this, view);
        }
    }
}